Skip to content

fix(explorer): move the filter cursor to the first match after layout - #1

Open
nihil2501 wants to merge 1 commit into
liamhawkins:fix/explorer-filter-enter-highlightedfrom
nihil2501:fix/explorer-filter-cursor-after-layout
Open

nihil2501 wants to merge 1 commit into
liamhawkins:fix/explorer-filter-enter-highlightedfrom
nihil2501:fix/explorer-filter-cursor-after-layout

Conversation

@nihil2501

Copy link
Copy Markdown

Builds on Maxteabag#335. Covers the nested case of Maxteabag#333, which the tests in Maxteabag#335 don't reach.

Summary

Typing a filter left the cursor on line 0 instead of the first match. Each keystroke rebuilds the tree from the snapshot, and _jump_to_current_match called move_cursor before the new nodes had a _line. With top-level connections, line 0 is the first match, so it went unnoticed. With tables under a connection, line 0 is the connection, so with Maxteabag#335:

  • type orders, Enter → the connection is selected
  • type orders, Down ×2, Enter → lands two rows short

The fix uses the deferral action_tree_filter_accept already had, pulled into a helper so both call sites share it:

 _update_tree_filter
   _restore_tree_from_snapshot
   _jump_to_current_match
-    move_cursor(node)
+    _call_after_refresh(move_cursor(node))
 action_tree_filter_accept
-  call_after_refresh(...) / synchronous fallback, inline
+  _call_after_refresh(_select_and_activate_after_refresh(node))

Evidence

300-table SQLite DB, filter t_29, Down ×3, Enter:

before-335
  • After: cursor starts on t_290, lands on t_293
after

Test plan

uv run pytest tests/ui/explorer/test_filter_accept_cursor_pilot.py -v
# test_filter_moves_cursor_to_first_nested_match               fails on #335, passes here
# test_filter_accept_activates_arrow_highlighted_nested_match  fails on #335, passes here

uv run pytest tests/ui/explorer -q
# 58 passed

Tree.move_cursor reads node._line, which is only set during the next
layout pass, not when add() runs. _jump_to_current_match called it right
after each keystroke's snapshot restore, so the cursor stayed on line 0
(the connection). Now that Enter activates cursor_node, filtering to a
table under a connection and pressing Enter selected the connection, and
arrow presses counted from the connection row. Defer the move via
call_after_refresh, as accept already does, and share that deferral in a
_call_after_refresh helper.

Refs Maxteabag#333.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant